home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Effect library / Demo ƒ / MSG Shell ƒ / msg sounds.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-12  |  1.9 KB  |  78 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        msg sounds.c
  4.  
  5. Purpose:    This module handles playing syncronous and asyncronous
  6.             sounds.
  7.  
  8.  
  9. MSG Demo -- graphic effects demonstration program
  10. Copyright (C) 1992-4 Mark Pilgrim & Dave Blumenthal
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg sounds.h"
  30.  
  31. SndChannelPtr        myChannel;
  32. Handle                MySounds[NUM_SOUNDS];
  33. Boolean                gSoundToggle;
  34. Boolean                gSoundAvailable;
  35.  
  36. void InitSounds(void)
  37. {
  38.     int                i;
  39.     
  40.     gSoundAvailable=(SndNewChannel(&myChannel, 0, 0L, 0L)==noErr);
  41.     if (!gSoundAvailable)
  42.         myChannel=0;
  43.     for (i=0; i<NUM_SOUNDS; i++)
  44.         MySounds[i]=0L;
  45. }
  46.  
  47. void DoSound(int whichSound, Boolean async)
  48. {
  49.     if (myChannel!=0)
  50.     {
  51.         SndDisposeChannel(myChannel, TRUE);
  52.         myChannel=0;
  53.     }
  54.     
  55.     whichSound-=1000;
  56.     if ((gSoundToggle) && (gSoundAvailable))
  57.     {
  58.         if (!MySounds[whichSound])
  59.             MySounds[whichSound]=GetResource('snd ', whichSound+1000);
  60.         
  61.         if (MySounds[whichSound])
  62.         {
  63.             if(SndNewChannel(&myChannel, 0, 0L, 0L) != noErr)                    
  64.             {
  65.                 myChannel = 0;
  66.                 gSoundAvailable = FALSE;
  67.             }
  68.             else SndPlay(myChannel, MySounds[whichSound], async);
  69.         }
  70.     }
  71. }
  72.  
  73. void CloseSounds(void)
  74. {
  75.     if(myChannel)
  76.         SndDisposeChannel(myChannel, TRUE);
  77. }
  78.